package cn.rxls.community.controller;


import cn.rxls.community.dto.booking.AddBookingDTO;
import cn.rxls.community.dto.booking.PageBookingDTO;
import cn.rxls.community.result.Result;
import cn.rxls.community.service.BookingService;
import cn.rxls.community.vo.booking.BookingVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 预约(Booking)表
 */
@RestController
@RequestMapping("booking")
@Validated
public class BookingController {
    /**
     * 服务对象
     */
    @Resource
    private BookingService bookingService;


    /**
     * 新增预约
     *
     * @param dto 参数对象
     * @return 预约结果
     */
    @PostMapping("/add")
    public Result<Boolean> addBooking(@Valid @RequestBody AddBookingDTO dto) {
        return Result.success(bookingService.addBooking(dto));
    }

    /**
     * 取消预约
     *
     * @param id 预约id
     * @return 预约结果
     */
    @GetMapping("/cancel")
    public Result<Boolean> addBooking(@Valid @NotNull(message = "非法预约编号") @RequestParam("id") Long id) {
        return Result.success(bookingService.cancelBooking(id));
    }


    /**
     * 根据状态分页查询
     *
     * @param dto 参数对象
     * @return 多条信息
     */
    @GetMapping("/page/state")
    public Result<List<BookingVO>> selectPageByState(@Valid @ModelAttribute PageBookingDTO dto) {
        return Result.success(bookingService.selectPageByState(dto));
    }

}

